/**
 * 系统设置控制器
 */
import './index.less'
import $_fn from '~plugins'

export default ['$scope','$rootScope','$location','$ui','http',function($scope,$rootScope,$location,$ui,http) {
    $scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($location.path())
    $scope.param = {}
    $scope.redErr = {}
    //警告提示
    $scope.errorToast = function(text) {
      $ui.toast({text:text,type:'warning',position:'center',appendTo:'.wp-container'});
    }
    //成功提示
    $scope.successToast = function(text) {
        $ui.toast({text:text,type:'success',position:'center',appendTo:'.wp-container'});
    }
    $scope.remlight = function(){                                                 //去除报错高亮
      for(var i in $scope.redErr){
        $scope.redErr[i] = false
      }
    }
    $scope.init = function(){
      http.post('getSystemSet.do',{},function (data) {
        if(data.errcode == 1){
          $scope.$apply(function(){
            $scope.data = data.data
          })
        }else{
          $scope.errorToast(data.errmsg)
        }
      })
    }
    $scope.init()

    $scope.skinSect = function(num){
      $scope.data.sys_skin = num
    }
    //
     $scope.ok = function(){
      if ($scope.data.bg_name=='' || $scope.data.bg_name==null || $scope.data.bg_name==undefined) {
        $scope.redErr.bg_name = true
        $scope.errorToast('请填写标题名称')
        return
      }
      let formData = {}
      formData.company_id = $scope.data.company_id
      formData.bg_name = $scope.data.bg_name
      formData.logo_url = $scope.data.logo_url
      formData.sys_skin = $scope.data.sys_skin
      // formData.overdue_times = $scope.data.overdue_times
      http.post('systemSet.do', formData, function (data) {
        if(data.errcode == 1){
          $scope.successToast(data.errmsg)
        }else{
          $scope.errorToast(data.errmsg)
        }
      })
    }

    $_fn.ueditorImg(function (data, _btn) {
      console.log('ueditorImg', data, _btn,$scope.data)
      $scope.$apply(function(){
        $scope.data.logo_url = data[0]
      })
    })
}]
